package net.lanelife.casino.caipiao.dto.admin;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;

import net.lanelife.casino.caipiao.entity.WithdrawRecord;
import net.lanelife.casino.caipiao.entity.WithdrawRecord_;
import net.lanelife.casino.common.dto.support.GenericTable;
import net.lanelife.casino.common.entity.json.serialize.CurrencySerializer;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Lists;

/**
 * @author Lane
 * 
 * 提款记录表格
 *
 * @param <DTO>
 */
public class WithdrawRecordTable<DTO> extends GenericTable<DTO, WithdrawRecord> {

	private static final long serialVersionUID = 1040006291770324347L;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountPending = 0D;
	@JsonSerialize(using = CurrencySerializer.class)
	private Double feePending = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountProcessing = 0D;
	@JsonSerialize(using = CurrencySerializer.class)
	private Double feeProcessing = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountAccepted = 0D;
	@JsonSerialize(using = CurrencySerializer.class)
	private Double feeAccepted = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountRejected = 0D;
	@JsonSerialize(using = CurrencySerializer.class)
	private Double feeRejected = 0D;

	public WithdrawRecordTable() {}

	public WithdrawRecordTable(Double amountPending, Double feePending,
			Double amountProcessing, Double feeProcessing,
			Double amountAccepted, Double feeAccepted, Double amountRejected,
			Double feeRejected) {
		super();
		this.amountPending = amountPending;
		this.feePending = feePending;
		this.amountProcessing = amountProcessing;
		this.feeProcessing = feeProcessing;
		this.amountAccepted = amountAccepted;
		this.feeAccepted = feeAccepted;
		this.amountRejected = amountRejected;
		this.feeRejected = feeRejected;
	}

	@Override
	public List<Selection<?>> buildExpression(Root<WithdrawRecord> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
		List<Selection<?>> columns = Lists.newArrayList();
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.PENDING), root.<Double>get(WithdrawRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.PENDING), root.<Double>get(WithdrawRecord_.fee)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.PROCESSING), root.<Double>get(WithdrawRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.PROCESSING), root.<Double>get(WithdrawRecord_.fee)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.ACCEPTED), root.<Double>get(WithdrawRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.ACCEPTED), root.<Double>get(WithdrawRecord_.fee)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.REJECTED), root.<Double>get(WithdrawRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(WithdrawRecord_.status), WithdrawRecord.Status.REJECTED), root.<Double>get(WithdrawRecord_.fee)).otherwise(0D)));
		return columns;
	}

	public Double getAmountPending() {
		return amountPending;
	}

	public void setAmountPending(Double amountPending) {
		this.amountPending = amountPending;
	}

	public Double getFeePending() {
		return feePending;
	}

	public void setFeePending(Double feePending) {
		this.feePending = feePending;
	}

	public Double getAmountAccepted() {
		return amountAccepted;
	}

	public void setAmountAccepted(Double amountAccepted) {
		this.amountAccepted = amountAccepted;
	}

	public Double getFeeAccepted() {
		return feeAccepted;
	}

	public void setFeeAccepted(Double feeAccepted) {
		this.feeAccepted = feeAccepted;
	}

	public Double getAmountRejected() {
		return amountRejected;
	}

	public void setAmountRejected(Double amountRejected) {
		this.amountRejected = amountRejected;
	}

	public Double getFeeRejected() {
		return feeRejected;
	}

	public void setFeeRejected(Double feeRejected) {
		this.feeRejected = feeRejected;
	}


	public Double getAmountProcessing() {
		return amountProcessing;
	}


	public void setAmountProcessing(Double amountProcessing) {
		this.amountProcessing = amountProcessing;
	}


	public Double getFeeProcessing() {
		return feeProcessing;
	}


	public void setFeeProcessing(Double feeProcessing) {
		this.feeProcessing = feeProcessing;
	}

}
